import QtQuick 2.0
import Toou2D 1.0
import QtQuick.Controls 2.2
import QtQuick.Dialogs
import Qt.labs.folderlistmodel
import cn.conchit 1.0


//图像操作列表
TRectangle{

    id: imageOperateArea
    //anchors.left: dividerLine3.right
    width: parent.width / 8 ;
    height: parent.height;
    color: "#196E6C";
    radius: 4
    theme.enabled: false;

    property bool normalMode : true;

    signal openImageFolder(string currentFolder)
    signal setSavePath(string currentFolder)

    signal openDealWithStep(int step);

    signal clearAll();

    signal removeLast();

    TLabel{
        id: imageOperateArea_head
        x:10;
        y:10;
        height: 20
        color: "#FFF"
        text: "图像操作" ;
        anchors.horizontalCenter: parent.horizontalCenter;
        theme.enabled: false;
    }

    TRectangle{
            anchors.top: imageOperateArea_head.bottom
            anchors.bottom: parent.bottom;
            width: parent.width
            color: "#002B36";
            theme.enabled: false;

            Column {
                anchors.centerIn: parent
                width: parent.width;
                spacing: parent.height / 16

                TButton{
                    anchors.horizontalCenter: parent.horizontalCenter
                    width: parent.width / 2
                    label.text: "打开文件夹"
                    background.color: "#196E6C"
                    label.color: "white"
                    theme.enabled: false

                    onClicked: function() {
                        folderDlialog.open()
                    }
                }

                TButton{
                    anchors.horizontalCenter: parent.horizontalCenter
                    width: parent.width / 2
                    label.text: "保存路径"
                    label.color: "white"
                    //label.font.bold: true;
                    background.color: "#196E6C"
                    //border.color: "#46A0FC"
                    theme.enabled: false

                    onClicked: function() {
                        savePathDlialog.open()
                    }
                }

                TButton{
                    anchors.horizontalCenter: parent.horizontalCenter
                    width: parent.width / 2
                    label.text: "上一张"
                    label.color: "white"
                    label.font.bold: true;
                    background.color: "#196E6C"
                    //border.color: "#46A0FC"
                    theme.enabled: false

                    onClicked: function() {
                        openDealWithStep(-1);
                    }
                }

                TButton{
                    anchors.horizontalCenter: parent.horizontalCenter
                    width: parent.width / 2
                    label.text: "下一张"
                    label.color: "white"
                    label.font.bold: true;
                    background.color: "#196E6C"
                    //border.color: "#46A0FC"
                    theme.enabled: false
                    onClicked: function() {
                        openDealWithStep(1);
                    }
                }

                TButton{
                    id:edit_btn
                    anchors.horizontalCenter: parent.horizontalCenter
                    width: parent.width / 2
                    label.text: "编辑"
                    label.color: "white"
                    label.font.bold: true
                    background.color: "#196E6C"
                    border.color: imageOperateArea.normalMode ? "white":"red"
                    theme.enabled: false
                    onClicked: function() {
                        imageOperateArea.normalMode = !imageOperateArea.normalMode
                        console.log("imageOperateArea.normalMode : " + imageOperateArea.normalMode)
                    }
                }

                TButton{
                    anchors.horizontalCenter: parent.horizontalCenter
                    width: parent.width / 2
                    label.text: "撤销"
                    label.color: "white"
                    label.font.bold: true;
                    background.color: "#196E6C"
                    //border.color: "#46A0FC"
                    theme.enabled: false
                    onClicked: function() {
                        removeLast();
                    }
                }

                TButton{
                    anchors.horizontalCenter: parent.horizontalCenter
                    width: parent.width / 2
                    label.text: "清空"
                    label.color: "white"
                    label.font.bold: true;
                    background.color: "#196E6C"
                    //border.color: "#46A0FC"
                    theme.enabled: false

                    onClicked: function() {
                        clearAll();
                    }
                }


            }


    }


    FolderDialog {
        id: folderDlialog
        acceptLabel: "确定"
        rejectLabel: "取消"
        options: FolderDialog.ShowDirsOnly
        onAccepted: {
            imageOperateArea.openImageFolder(currentFolder)
        }
    }

    FolderDialog {
        id: savePathDlialog
        acceptLabel: "确定"
        rejectLabel: "取消"
        options: FolderDialog.ShowDirsOnly
        onAccepted: {
            imageOperateArea.setSavePath(currentFolder)
        }
    }

    FileDialog {
        id: fileDialog
        fileMode: FileDialog.OpenFiles
//        nameFilters: ["图像文件 (*.png *.jpg *.gif *.bmp)", "全部文件 (*.*)"]
        options :FolderDialog.ShowDirsOnly

        onAccepted: {

        }
        onRejected:{
        }
    }
}



